package LinkList;

import java.util.List;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: LinkList
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-10-23  08:15
 * @Description: TODO
 * @Version: 1.0
 */
public class 环形链表141 {

    class ListNode {
        int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public boolean hasCycle(ListNode head) {
        // 当链表为空时候表示没有环状
        if (head == null) {
            return false;
        }
        ListNode fast = head;
        ListNode slow = head;
        // 判断快指针是否已经到了末尾 如果是的末尾 那就表示没有
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            // 如果有环的话，那就有可能会遇
            if (fast == slow) {
                return true;
            }
        }
        return false;
    }
}
